package learningApp.Function;


import java.io.*;

import learningApp.Accessories.VariableAssignment;

public class UserDefinedFunction implements IConcentratedFunction {

	private int _dimension;
	
	public UserDefinedFunction(int dimension)
	{
		_dimension = dimension;
	}
	
	@Override
	public double Query(VariableAssignment assignment) {
		
		String assignStr = "";
		for(int k : assignment)
		{
			assignStr += k+" ";
		}
		System.out.println("What is the value of: "+assignStr);
		
		
		
		double output;
		
		while(true)
		{
			String input = getStringFromUser();
			try
			{
				output = Double.parseDouble(input);
				break;
			}
			catch(Exception e)
			{
				if(input.toUpperCase() == "Q")
				{
					return Double.NaN;
				}
			}
		}
		return output;

	}
	
	private String getStringFromUser()
	{
		BufferedReader in =
				new BufferedReader(new InputStreamReader(System.in));
			String s = null;
			try {
				s = in.readLine();
			} catch (IOException e) {
				return "";
			}		
			return s;
	}

	@Override
	public boolean IsInitialized() {
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	public int GetDimension()
	{
		return _dimension;
	}

}
